package org.micode.demo.db.dao;

import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.ResultType;
import org.apache.ibatis.annotations.Select;
import org.micode.demo.db.domain.dto.SysDictionaryDTO;
import org.micode.demo.db.vo.IdNameVO;
import org.micode.libs.dao.base.BaseAllDao;

import java.util.List;

/**
 * 字典配置信息(sys_dictionary) 实体类的Dao
 *
 * @author: wutianbin
 * @version: v1.0.24
 * @CreateDate: 2021-09-06
 */
@Mapper
public interface SysDictionaryDao extends BaseAllDao<SysDictionaryDTO> {
    // 非常规sql写这里--- xml 自动生成,不再手动在xml中写sql !!

    @Select(" <script>" +
            "SELECT id, concat(param_type, ':', param_name) as name " +
            " FROM sys_dictionary " +
            " WHERE 1 = 1 " +
            "   <if test=\"paramType != null and paramType != ''\">" +
            "      AND param_type = #{paramType}" +
            "   </if>" +
            " ORDER BY param_type, sort_no" +
            " </script>")
    @ResultType(IdNameVO.class)
    List<IdNameVO> listIdNameByType(@Param("paramType") String paramType);

    @Select(" <script>" +
            " SELECT * FROM sys_dictionary " +
            " WHERE 1 = 1 " +
            "   <if test=\"paramType != null and paramType != ''\"> " +
            "      AND param_type = #{paramType} " +
            "   </if>" +
            " ORDER BY param_type, sort_no " +
            " </script>")
    @ResultType(SysDictionaryDTO.class)
    List<SysDictionaryDTO> listByParamType(@Param("paramType") String paramType);

}
